﻿<div class="page-quote">
    <blockquote class="layui-elem-quote">错误日志列表</blockquote>
</div>

<div class="page-query">
    <form class="layui-form" id="formQueryErrorLog">
        <div class="layui-inline">
            <label class="layui-form-label">UserId</label>
            <div class="layui-input-block">
                <input type="text" name="UserId" placeholder="" class="layui-input" autocomplete="off">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">IP</label>
            <div class="layui-input-block">
                <input type="text" name="IP" placeholder="" class="layui-input" autocomplete="off">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">ErrorInfo</label>
            <div class="layui-input-block">
                <input type="text" name="ErrorInfo" placeholder="" class="layui-input" autocomplete="off">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">发生时间</label>
            <div class="layui-input-block">
                <input type="text" id="OperateTime_errorLog" placeholder="" class="layui-input" autocomplete="off" value="@DateTime.Now.Date.AddMonths(-6).ToString("yyyy-MM-dd") ~ @DateTime.Now.Date.ToString("yyyy-MM-dd")" readonly="readonly">
                <input type="hidden" id="beginTime_errorLog" name="beginTime" value="@DateTime.Now.Date.AddMonths(-6).ToString("yyyy-MM-dd")" />
                <input type="hidden" id="endTime_errorLog" name="endTime" value="@DateTime.Now.Date.ToString("yyyy-MM-dd")" />
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <button type="button" class="layui-btn" onclick="ErrorLogList.query()">查询</button>
            </div>
        </div>
    </form>
</div>

<div class="page-tool">
    <div class="layui-btn-group">
    </div>
</div>
<div class="page-list">
    <table id="tableErrorLog" lay-filter="tableList"></table>
</div>

<script>
    var ErrorLogList = function () {
        let inited = false;
        let data = {};
        var table;

        function initData() {
            layui.use(['form', 'layer', 'table', 'element', 'laydate'], function () {

                //日期控件
                var laydate = layui.laydate;
                laydate.render({
                    elem: '#OperateTime_errorLog'
                    , range: '~'
                    , done: function (value, beginDate, endDate) {
                        $('#beginTime_errorLog').val(beginDate.year + '-' + beginDate.month + '-' + beginDate.date);
                        $('#endTime_errorLog').val(endDate.year + '-' + endDate.month + '-' + endDate.date);
                    }
                });

                //加载数据
                loadData();

                //给工具条注册点击事件
                layui.table.on('tool(tableList)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                    var id = obj.data.id;

                });

            });

        }

        function loadData() {
            var data = $('#formQueryErrorLog').serializeJson();

            layui.table.render({
                elem: '#tableErrorLog'
                , height: 670
                , url: '/SysLog/GetErrorLogList' //数据接口
                , where: data
                , page: true //开启分页
                , limit: 15
                , cols: [[ //表头
                    { field: 'id', title: 'ID', width: 100, sort: true }
                    , { field: 'ip', title: 'IP', width: 160 }
                    , { field: 'errorInfo', title: 'ErrorInfo' }
                    , { field: 'userId', title: '用户ID', width: 160 }
                    , {
                        field: 'createTime', title: '发生时间', templet: function (d) {
                            return layui.util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss");
                        }, width: 160
                    }
                    //, { field: '', title: '操作', width: 150, align: 'center', toolbar: '#barTool' }
                ]]
                , done: function (res, curr, count) {//请求数据完成时，关闭加载loading
                    console.log(res);
                }

            });


        }

        return {
            init() {//初始化
                if (!inited) {
                    initData();
                    inited = true;
                }
            },
            query() {//查询
                loadData();
            },
        };
    }();
</script>
